package org.eece262.taskshareserver;

import java.util.LinkedList;

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.edu.eece262.taskshare.Messages;

@PersistenceCapable
public class Change {
	
	public class EntryType {
		public static final int TASK = 0;
		public static final int CONTACTPAIR = 1;
		public static final int GROUP = 2;
	};

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private LinkedList<String> changeUsersAffected;

	@Persistent
	private long changeTimestamp;
	
	@Persistent
	private int changeType; 
	
	@Persistent
	@Embedded
	private Task changeTask;
	
	@Persistent
	@Embedded
	private ContactPair changeContactPair;
	
	@Persistent
	@Embedded
	private Group changeGroup;
	
	public Change(int entry) {
		changeUsersAffected = new LinkedList<String>();
		changeTimestamp = System.currentTimeMillis();
		changeTask = new Task(new Messages.Task(), null, false);
		changeContactPair = new ContactPair("", "", -1);
		changeGroup = new Group();
		changeType = entry;
	}

	public Key getKey() {
		return key;
	}

	public LinkedList<String> getUsersAffected() {
		return changeUsersAffected;
	}

	public Change setUsersAffected(LinkedList<String> usersAffected) {
		this.changeUsersAffected = usersAffected;
		return this;
	}
	
	public Change addUsersAffected(User user) {
		this.changeUsersAffected.add(user.getUsername());
		return this;
	}
	
	public Change addUsersAffected(String user) {
		this.changeUsersAffected.add(user);
		return this;
	}

	public Task getTask() {
		return changeTask;
	}

	public Change setTask(Task task) {
		this.changeTask = task;
		return this;
	}

	public Group getGroup() {
		return changeGroup;
	}

	public Change setGroup(Group group) {
		this.changeGroup = group;
		return this;
	}

	public long getTimestamp() {
		return changeTimestamp;
	}

	public void setTimestamp(long timestamp) {
		this.changeTimestamp = timestamp;
	}

	public ContactPair getContactPair() {
		return changeContactPair;
	}

	public Change setContactPair(ContactPair contactPair) {
		this.changeContactPair = contactPair;
		return this;
	}

	public int getChangeType() {
		return changeType;
	}

	public void setChangeType(int changeEntryType) {
		this.changeType = changeEntryType;
	}
}
